﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DepartmentsChecking : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        if (Utility.HasNullValue(e.NewValues))
        {
            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "输入不能为空！";
            e.Cancel = true;
            return;
        }

        string score = e.NewValues["ScoreBySegment"].ToString();
        bool valid = true;
        int result;
        if (!int.TryParse(score, out result) || result < 0 || result > 100)
        {
            valid = false;
        }

        score = e.NewValues["LeaderScore"].ToString();
        if (!int.TryParse(score, out result) || result < 0 || result > 100)
        {
            valid = false;
        }

        // Set the error message label.
        if (!valid)
        {
            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "请确定评分在0~100之间。";
            e.Cancel = true;
        }
        else
            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "";
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Utility.FormatGridview(GridView1, e);

        if (e.Row.RowType == DataControlRowType.Header)
        {
            for (int i = 0; i < GridView1.Columns.Count; i++)
            {
                if (e.Row.Cells[i].Text == "部门名称" || e.Row.Cells[i].Text == "部门主管")
                {
                    GridView1.Columns[i].ItemStyle.Width = 64;
                }
            }
        }
    }
}
